package algorithm.arithmetic.找完数;

/**
 * @author xinchen by 2016/11/28
 * @version 1.0
 */
public class Solution {
    // 一个数如果恰好等于它的因子之和，这个数就称为 "完数 "。例如6=1＋2＋3.编程找出N以内的所有完数
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        StringBuilder result = new StringBuilder();
        for (int i = 2; i <= n; i++) {
            if (isWanshu(i)) {
                result.append(i).append(' ');
            }
        }
        System.out.println(result.toString().trim());
    }

    private static boolean isWanshu(int num) {
        int sum = 0;
        for (int i = 1; i <= num / 2; i++) {
            if (num % i == 0) {
                sum += i;
            }
        }
        return sum == num;
    }
}
